package com.colin.userservice9001.service.impl;

import cn.dev33.satoken.stp.SaTokenInfo;
import cn.dev33.satoken.stp.StpUtil;
import com.colin.common.bean.User;
import com.colin.common.response.R;
import com.colin.userservice9001.mapper.UserMapper;
import com.colin.userservice9001.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public R<SaTokenInfo> login(User user) {
        user = userMapper.selectUser(user.getUsername(), user.getPassword());

        if (user != null) {
            StpUtil.login(user.getId());
            SaTokenInfo tokenInfo = StpUtil.getTokenInfo();
            return R.ok(tokenInfo);
        }

        return R.error();
    }
}
